package com.wen.Interceptor;



import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


@Component
public class LoginInterceptor extends HandlerInterceptorAdapter {
    @Override
    public boolean preHandle(HttpServletRequest request,
                             HttpServletResponse response,
                             Object handler) throws Exception {
        System.out.println("执行了prehandle");
        if (request.getSession().getAttribute("user") == null) {
            System.out.println(request.getSession().getAttribute("user"));
            response.sendRedirect("/admin");
            return false;
        }
        return true;
    }
}
